package com.kitty.game.pk.facade;

import com.kitty.common.utils.SpringUtils;
import com.kitty.game.pk.message.ReqGotoPk;
import com.kitty.game.pk.message.ReqPkInfo;
import com.kitty.game.pk.message.ReqZuolaoPlead;
import com.kitty.game.pk.message.ReqZuolaoRelease;
import com.kitty.game.pk.service.PkService;
import com.kitty.game.role.model.Role;
import com.kitty.listener.EventType;
import com.kitty.listener.annotation.EventHandler;
import com.kitty.listener.event.EnterMapEvent;
import com.kitty.mina.annotation.RequestMapping;
import com.kitty.mina.cache.SessionUtils;
import org.apache.mina.core.session.IoSession;
import org.springframework.stereotype.Controller;

@Controller
public class PkController {
    @RequestMapping
    public void reqZuolaoPlead(IoSession session, ReqZuolaoPlead reqZuolaoPlead) {
        Role role = SessionUtils.getRoleBySession(session);
        SpringUtils.getBean(PkService.class).pleadForPrisoner(role, Long.parseLong(reqZuolaoPlead.getGid()), reqZuolaoPlead.getName());
    }

    @RequestMapping
    public void reqZuolaoRelease(IoSession session, ReqZuolaoRelease reqZuolaoRelease) {
        Role role = SessionUtils.getRoleBySession(session);
        SpringUtils.getBean(PkService.class).releasePrisoner(role, Long.parseLong(reqZuolaoRelease.getGid()), reqZuolaoRelease.getName());
    }

    @RequestMapping
    public void reqPkInfo(IoSession session, ReqPkInfo reqPkInfo) {
        Role role = SessionUtils.getRoleBySession(session);
        SpringUtils.getBean(PkService.class).viewForcePkInfo(role, reqPkInfo.getType(), reqPkInfo.getPara1(), reqPkInfo.getPara2());
    }

    @RequestMapping
    public void reqGotoPk(IoSession session, ReqGotoPk reqGotoPk) {
        Role role = SessionUtils.getRoleBySession(session);
        SpringUtils.getBean(PkService.class).transferForcePk(role, Long.parseLong(reqGotoPk.getGid()));
    }

    @EventHandler(EventType.ENTER_MAP)
    public void handleEnterMapEvent(EnterMapEvent enterMapEvent) {
        Role role = enterMapEvent.getRole();
        SpringUtils.getBean(PkService.class).checkEnterMap(role);
    }
}
